package edu.java.homework.hw03.ipj05;

public class J01 {

    /**
     *
     * @param args
     */
    public static void main(String[] args) {
	int[] arr = { 1, 2, 3, 4, 5, 2, 3, 5, 10, 21, 1, 3, 2, 15 };
	// int[] arr=null;
	int result = countAppearancesOfNumberInArray(arr, 15);
	System.out.println("Count: " + result);
    }

    /**
     * Returns counts of appearances of the input number in the array.
     * 
     * @param array
     *            the array where to search the number
     * @param number
     *            the number for searching
     * @return the count of appearances of the number in the array
     * @throws IllegalArgumentException
     *             if the input array is empty
     */
    public static int countAppearancesOfNumberInArray(int[] array, int number) {
	if (array == null) {
	    throw new IllegalArgumentException(
		    "The array is null pointed. Incorrect input.");
	}
	int counts = 0;
	for (int index = 0; index < array.length; index++) {
	    if (number == array[index]) {
		counts++;
	    }
	}
	return counts;
    }

}
